﻿package  plugins.mstandio.UniversalMap.cameras{
	
	/**
	 * ...
	 * @author mstandio
	 */		
	 
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	import flash.display.Bitmap;
	import flash.display.BitmapData;	 
	
	import plugins.mstandio.UniversalMap.cameras.Cam;	
	import plugins.mstandio.UniversalMap.navigation.MapButton;
	
	public class Cam_border extends Cam {		
						
		private var cam:Sprite;
		private var topButtonShowing:MapButton;
		
		public function Cam_border(initPan:Number, initTilt:Number, initZoom:Number, camSize:Number, panShift:Number, camColor:String) :void {
			super(initPan, initTilt, initZoom, camSize, panShift, camColor);			
									
			this.topButtonShowing = new MapButton();
			this.topButtonShowing.drawButton(MapButton.BUTTON_SHOWING,this.camSize);
			this.topButtonShowing.visible = false;
						
			this.cam = new Sprite();	
			this.drawCone(this.cam, this.initZoom);
			this.addChild(this.cam);				
			
			this.addChild(topButtonShowing);		
		}
		
		private function drawCone(cam:Sprite, zoom:Number):void {
			this.cam.graphics.clear();
			var r:Number = 80 * this.camSize;
			var a:Number = zoom*0.051 +0.55; // why ?
			var x:Number = (r * Math.sin(a));
			var y:Number = (Math.sqrt(r * r - x * x));
			
			cam.graphics.beginFill(Number(this.camColor),0.75);
			cam.graphics.lineStyle(2*this.camSize,0x000000,0.75);
			cam.graphics.moveTo(0, 0);
			cam.graphics.lineTo(x, y);						
			cam.graphics.curveTo(2*r-x, 0, x, -y);						
			cam.graphics.endFill();								
			
			this.rotate(this.initPan, this.initTilt);
		}				
			
		public override function rotate(pan:Number, tilt:Number):void {					
			this.cam.rotation = pan + this.panShift;
			this.cam.scaleX = 1 - Math.abs(tilt) / 100;		  
			
			this.initPan = pan;
			this.initTilt = tilt;
			
			if (tilt > 0) {
				this.topButtonShowing.visible = true;
			}else{
				this.topButtonShowing.visible = false;
			}
		}
		
		public override function zoom(zoom:Number):void {				
			this.initZoom = this.validateZoom(zoom);
			drawCone(cam, this.initZoom);						
		}				
	}		
}